import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:mini_black_box/global/my_colors.dart';
import 'package:mini_black_box/global/my_styles.dart';
import 'package:mini_black_box/screens/community_screen.dart';
import 'package:mini_black_box/screens/game_screen.dart';
import 'package:mini_black_box/screens/home/home_screen.dart';
import 'package:mini_black_box/screens/my_screen.dart';
import 'package:mini_black_box/utils/color_util.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '小黑盒',
      theme: ThemeData(
        primarySwatch: createMaterialColor(primary),
        fontFamily: 'NotoSansSC',
        // 去除水波纹
        splashColor: Colors.transparent,
        highlightColor: Colors.transparent,
      ),
      debugShowCheckedModeBanner: false,
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _current = 0;

  final List<Widget> _screenList = [
    const HomeScreen(),
    const CommunityScreen(),
    const GameScreen(),
    const MyScreen(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _screenList.elementAt(_current),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _current,
        onTap: (index) => setState(() => _current = index),
        selectedItemColor: primary,
        unselectedItemColor: lighter,
        selectedLabelStyle: label,
        unselectedLabelStyle: label,
        type: BottomNavigationBarType.fixed,
        items: const [
          BottomNavigationBarItem(
            icon: Icon(Icons.home_outlined),
            label: '首页',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.circle_outlined),
            label: '社区',
          ),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.close_outlined,
              size: 30.0,
            ),
            label: '游戏库',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.square_outlined),
            label: '我',
          ),
        ],
      ),
    );
  }
}
